<html>
<head><meta charset="utf-8"><title>Using r-a on nrf-hal · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html">Using r-a on nrf-hal</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214965999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/214965999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#214965999">(Oct 29 2020 at 13:30)</a>:</h4>
<p>I'd like to use rust-analyzer on this repo: <a href="https://github.com/nrf-rs/nrf-hal/">https://github.com/nrf-rs/nrf-hal/</a></p>
<p>The problem is that it contains a big, shared crate, nrf-hal-common, that uses non-additive Cargo features. The workspace also contains a bunch of crates that enable precisely one of those features and reexport the resulting library contents. This causes r-a to think it has to enable <em>all</em> features when running <code>cargo check</code> and performing analysis, which breaks with the way the shared crate is designed.</p>
<p>Is there any way to fix this, or would we have to implement more advanced features, like on-the-fly <code>#[cfg]</code> modification to get this to work?</p>
<p>(I could live without check-on-save, but at least IDE functionality would be nice)</p>



<a name="215031472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215031472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215031472">(Oct 29 2020 at 21:34)</a>:</h4>
<p>This is similar to what <span class="user-mention" data-user-id="116114">@Paul Faria</span> has been looking at, around configuration mgmt in the rust-project.json -based flows.  I think we'd need more complex handling of <code>cfg</code> than we currently have (either on-the-fly, or multiple instances of a crate in the db based the features that were enabled as it was encountered in the dependency tree.</p>



<a name="215032048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215032048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215032048">(Oct 29 2020 at 21:39)</a>:</h4>
<p>It's actually handling them generically internally, but have different UI at the IDE interface. Though this case is different from what I was considering in use cases. I was taking into consideration different features toggled on and off as the "active" configuration. This is about having different features active at certain points in the crate graph, right <span class="user-mention" data-user-id="211727">@Jonas Schievink</span>?</p>



<a name="215032249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215032249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215032249">(Oct 29 2020 at 21:41)</a>:</h4>
<p>Oh wait. I think this is also a limitation of cargo. I have a similar scenario in coi where I have to manage my tests with makefiles because the workspace as a whole requires all of the features to match at the top level.</p>



<a name="215032262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215032262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215032262">(Oct 29 2020 at 21:41)</a>:</h4>
<p>I missed the detail about the workspace</p>



<a name="215032373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215032373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215032373">(Oct 29 2020 at 21:42)</a>:</h4>
<p>I think what I'm working on might help in that case. I actually hadn't gotten to the point where I'd considered workspaces yet but this will be helpful when I get there.</p>



<a name="215032415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215032415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215032415">(Oct 29 2020 at 21:43)</a>:</h4>
<p>Yeah, <code>cargo check</code> does not work if you do it on the nrf-hal workspace. I don't really mind that, since it still works fine in the individual subcrates. Mostly I just want r-a's IDE features.</p>



<a name="215032463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215032463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215032463">(Oct 29 2020 at 21:43)</a>:</h4>
<p>I might implement on-the-fly switching of features/cfgs then (just for r-a, not Cargo)</p>



<a name="215033777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215033777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215033777">(Oct 29 2020 at 21:57)</a>:</h4>
<p>Oh, that's what I'm currently working on <span aria-label="grinning face with smiling eyes" class="emoji emoji-1f601" role="img" title="grinning face with smiling eyes">:grinning_face_with_smiling_eyes:</span></p>



<a name="215033958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215033958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215033958">(Oct 29 2020 at 21:58)</a>:</h4>
<p>Ah, alright, go ahead then :)</p>



<a name="215084516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084516">(Oct 30 2020 at 11:56)</a>:</h4>
<p>I think <code>cargo check</code> is unfortunately unfixable. The best we can do is to override check on save command to </p>
<p><code>cargo check -p p1 &amp;&amp; cargo check -p p2 &amp;&amp; cargo check -p p3</code> etc</p>



<a name="215084605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084605">(Oct 30 2020 at 11:58)</a>:</h4>
<p>Our own analysis... that's tricky</p>



<a name="215084668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084668">(Oct 30 2020 at 11:58)</a>:</h4>
<p>I think this is a different problem than the one <span class="user-mention" data-user-id="116114">@Paul Faria</span> is working on :-) Or at least, there are two orthogonal problems</p>



<a name="215084714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084714">(Oct 30 2020 at 11:59)</a>:</h4>
<p>One is:</p>
<ul>
<li>we have two crates in the crate graph for the same file, how do we pick the right one for goto def and such?</li>
</ul>
<p>The second is:</p>
<ul>
<li>we want to have different crates for different files with <em>different features</em></li>
</ul>



<a name="215084729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084729">(Oct 30 2020 at 11:59)</a>:</h4>
<p>ie, it is the problem of creating a CrateGraph out of cargo metadata.</p>



<a name="215084843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084843">(Oct 30 2020 at 12:00)</a>:</h4>
<p>I think the second one should be more straightforward to fix, by only changing <code>to_crate_graph</code> function</p>



<a name="215084922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084922">(Oct 30 2020 at 12:01)</a>:</h4>
<p>Specifically, we currently eagarly activate all features of all packages present in <code>cargo metadata</code>. I think we can fix that to activate only some features, and fork internal packages as needed</p>



<a name="215084989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Using%20r-a%20on%20nrf-hal/near/215084989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Using.20r-a.20on.20nrf-hal.html#215084989">(Oct 30 2020 at 12:02)</a>:</h4>
<p><em>Ideally</em>, we'd just ask Cargo for unit-graph (cargo metadata 2.0 in the works), but we can hack this manually</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>